package com.Advance.Signle_;
//展示懒汉式实现
public class signle02 {
    public static void main(String[] args) {
        Dog dog = Dog.getInstance();
        System.out.println(dog);
        Dog dog2 = Dog.getInstance();
        System.out.println(dog2);
        System.out.println(dog == dog2);
    }
}
//以一个人只能样一条狗为例
class Dog{
    private String name;
    private static Dog dog ;
    public Dog(String name) {
        this.name = name;
        System.out.println("构造器被调用");
    }
    public static Dog getInstance() {
        if (dog == null) {
           dog =  new Dog("小黄");
        }
        return dog;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                '}';
    }
}
//当用户使用时才返回对象，弊端就是存在线程安全问题
